#ifndef AppComponent_hpp
#define AppComponent_hpp

#include <oatpp/parser/json/mapping/ObjectMapper.hpp>
#include <oatpp/web/server/HttpConnectionHandler.hpp>
#include <oatpp/network/tcp/server/ConnectionProvider.hpp>
#include <oatpp/core/macro/component.hpp>
#include <oatpp-websocket/oatpp-websocket/ConnectionHandler.hpp>
#include "webSocket/fileListener.h"

class AppComponent
{
    public:
        OATPP_CREATE_COMPONENT(std::shared_ptr<oatpp::network::ServerConnectionProvider>,serverConnectionProvider)
        ([]{return oatpp::network::tcp::server::ConnectionProvider::createShared({"0.0.0.0",8510,oatpp::network::Address::IP_4});}());

        OATPP_CREATE_COMPONENT(std::shared_ptr<oatpp::web::server::HttpRouter>,httpRouter)
        ([]{return oatpp::web::server::HttpRouter::createShared();}());

        OATPP_CREATE_COMPONENT(std::shared_ptr<oatpp::network::ConnectionHandler>,serverConnectionHandler)
        (
            "http",
            []{
                OATPP_COMPONENT(std::shared_ptr<oatpp::web::server::HttpRouter>,router);
                return oatpp::web::server::HttpConnectionHandler::createShared(router);
            }()
        );

        OATPP_CREATE_COMPONENT(std::shared_ptr<oatpp::data::mapping::ObjectMapper>,apiObjectMapper)
        ([]{
            return oatpp::parser::json::mapping::ObjectMapper::createShared();
        }());

        OATPP_CREATE_COMPONENT(std::shared_ptr<oatpp::network::ConnectionHandler>,websocketConnectionHandler)
        (
            "websocket",
            []{
                auto connectionHandler=oatpp::websocket::ConnectionHandler::createShared();
                connectionHandler->setSocketInstanceListener(std::make_shared<wsFileInstanceListener>());
                return connectionHandler;
            }()
        );
};

#endif